﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class PlayerDetial : MonoBehaviour {

	// Use this for initialization
	void Start () {
		EventTriggerListener.Get (gameObject).onClick = HideView;
		evt.ServerEventDispather.getInstance ().AddEventDispather(evt.ServerEvent.SHOW_PLAYER_DETAIL,ShowView);
		evt.ServerEventDispather.getInstance ().AddEventDispather(evt.ServerEvent.SHOW_MAIN_DETAIL,ShowMainPlayer);
	}

	private void ShowView(object go){

		ZjhPlayer zjh = go as ZjhPlayer;
		transform.GetChild (2).GetComponent<Image> ().sprite = zjh.Head.sprite;
		transform.GetChild (3).GetComponent<Text> ().text = zjh.P_name;
		transform.GetChild (4).GetComponent<Text> ().text = "ID: "+zjh.Id;

		string ip = "";

		for( int i = 0 ; i < info.UserInfo.room.seats.Count ; i++ ){
			if(info.UserInfo.room.seats[i].playerId == zjh.Id){
				ip = info.UserInfo.room.seats [i].ip;
			}
		}
		transform.GetChild (5).GetComponent<Text> ().text = "IP: "+ip;
		transform.localPosition = Vector3.zero;
	}

	private void ShowMainPlayer(object go){
		transform.GetChild (2).GetComponent<Image> ().sprite = go as Sprite;
		transform.GetChild (3).GetComponent<Text> ().text = info.UserInfo.UserData.nickName;
		transform.GetChild (4).GetComponent<Text> ().text = "ID: "+info.UserInfo.UserData.id;
		transform.GetChild (5).GetComponent<Text> ().text = "IP: "+info.UserInfo.UserData.ip;
		transform.localPosition = Vector3.zero;
	}

	private void HideView(GameObject go){
		transform.localPosition = new Vector3 (10000,0,0);
	}

	// Update is called once per frame
	void Update () {
	
	}
}
